package com.mz.mattress.admin.api.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mz.mattress.admin.api.req.SaleQueryReq;
import com.mz.mattress.admin.service.SaleService;
import com.mz.mattress.api.common.Constants;
import com.mz.mattress.api.common.Result;
import com.mz.mattress.api.entity.Sale;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Set;

@Slf4j
@RestController
@RequestMapping(Constants.ADMIN_PATH + "sale")
public class SaleController {

    @Autowired
    private SaleService saleService;

    @GetMapping("/listPage")
    public Result<IPage<Sale>> listPage(SaleQueryReq req) {
        return saleService.listPage(req);
    }

    @GetMapping(value = "/{id}")
    public Result<Sale> detail(@PathVariable Integer id) {
        return saleService.getById(id);
    }

    @PostMapping
    public Result add(@RequestBody Sale sale) {
        return saleService.add(sale);
    }

    @PutMapping
    public Result update(@RequestBody Sale sale) {
        return saleService.updateById(sale);
    }

    @DeleteMapping
    public Result delete(@RequestBody Set<Integer> ids) {
        return saleService.deleteByIds(ids);
    }

}
